package com.qf.service.impl;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheKey;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheRemove;
import com.netflix.hystrix.contrib.javanica.cache.annotation.CacheResult;
import com.qf.feign.GoodsFeign;
import com.qf.pojo.Goods;
import com.qf.service.TestCacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 千峰教育
 * @Company http://www.mobiletrain.org/
 * @Version 1.0
 */
@Service
public class TestCacheServiceImpl implements TestCacheService {

    @Autowired
    GoodsFeign goodsFeign;

    @HystrixCommand(commandKey = "findByCondition")
    //缓存结果
    @CacheResult
    @Override
    public Goods testCache(Integer id) {
        return goodsFeign.findById(id);
    }

    @HystrixCommand
    @CacheRemove(commandKey = "findByCondition")
    @Override
    public void clearCache(@CacheKey Integer id) {
        System.out.println("缓存被清空");
    }
}
